package com.whu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.whu.aircraft.TrackInfo;
import com.whu.aircraft.User;
import com.whu.dao.interfaces.TrackInfoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TrackInfoService {
    final TrackInfoDao trackInfoDao;

    public TrackInfoService(TrackInfoDao trackInfoDao) {
        this.trackInfoDao = trackInfoDao;
    }

    public List<TrackInfo> list() throws JsonProcessingException {
        QueryWrapper<TrackInfo> queryWrapper = new QueryWrapper<>();
        List<TrackInfo> trackInfoList = trackInfoDao.selectList(queryWrapper);
        for(TrackInfo trackInfo:trackInfoList){
            trackInfo.json2List();
        }
        return trackInfoList;
    }

    public IPage<TrackInfo> listWithPage(int page,int num) throws JsonProcessingException {
        Page<TrackInfo> pager = new Page<>(page,num);
        QueryWrapper<TrackInfo> queryWrapper = new QueryWrapper<>();
        IPage<TrackInfo> iPage = trackInfoDao.selectPage(pager,queryWrapper);
        for(TrackInfo trackInfo:iPage.getRecords()){
            trackInfo.json2List();
        }
        return iPage;
    }
    public void create(TrackInfo trackInfo) throws JsonProcessingException {
        trackInfo.list2Json();
        trackInfoDao.insert(trackInfo);
    }
    public void delete(Long id){
        trackInfoDao.deleteById(id);
    }
}
